home *** CD-ROM | disk | FTP | other *** search
- /*
- FILENAME
- GlobalData.c
-
- DESCRIPTION
- Contains code that shows an alternate way to manage unique global
- data for different message handler instances. This method does
- not require that you access the global data via a message override,
- so it works great for callback situations. (Remember, global data
- set up by NewMessageGlobals and so forth can only be accessed when
- you've gained control through a message override. These global
- data routines work whenever and however you've gained control.)
-
- We don't need to do things this way for this driver, (the normal
- QuickDraw GX global data routines will work fine), but I figured we
- needed an example of this method, so here it is. Note that the
- SetDriverGlobals and GetDriverGlobals routines are in NewApp.a.
-
- COPYRIGHT
- Copyright © 1995 Apple Computer, Inc.
- All rights reserved.
-
- Modification history
- 05/03/95 - Dave Hersey - Version 1.0.1 to fix some minor bugs in
- CustomBufferingAndIO.c.
-
- 01/14/95 - Dave Hersey - Begat.
-
- NOTE: Relevant goodies are listed in MPW's "Mark" menu.
-
- */
-
- #include "CommonDefines.h"
-
-
- /* -----------------------------------------------------------------------
-
- CreateAndStoreGlobals is a routine we call to initialize and store a
- handle in the are we allocated at the end of our NewApp.a jump table.
-
- This routine and its counterpart (DisposeGlobals) provide an alternate
- method of handling global data in a driver. The two calls provide a
- method similar to GetMessageHandlerInstanceContext and
- SetMessageHandlerInstanceContext, except that this method can be used
- even if your code didn't receive control via a message override. For
- example, if your code is being executed from a dialog manager
- callback. The standard global data handling routines that are provided
- with QuickDraw GX will only work if your code received control via a
- message override.
-
- ----------------------------------------------------------------------- */
-
- OSErr CreateAndStoreGlobals(DriverGlobalsHdl *drvrGlobalsHdl)
- {
- OSErr anErr;
-
- // Create a handle for our data, and store it in our jump table's
- // data area. Note that the routine SetDriverGlobals is in NewApp.a.
-
- *drvrGlobalsHdl = (DriverGlobalsHdl) TempNewHandle(sizeof(DriverGlobals), &anErr);
-
- if (!anErr)
- {
- (**drvrGlobalsHdl)->curFileRefNum = 0;
- SetDriverGlobals(*drvrGlobalsHdl);
- }
-
- return anErr;
- }
-
-
- /* -----------------------------------------------------------------------
-
- DisposeGlobals is a routine that disposes of the global data we stored
- in our jump table's data area via CreateAndStoreGlobals.
-
- ----------------------------------------------------------------------- */
-
- void DisposeGlobals()
- {
- DriverGlobalsHdl drvrGlobalsHdl;
-
- // If a handle was stored in our jump table's global data area,
- // dispose of it and store nil in its place. This indicates
- // that no valid globals are allocated. Note that the routine
- // GetDriverGlobals is in NewApp.a.
-
- drvrGlobalsHdl = GetDriverGlobals();
-
- if (drvrGlobalsHdl != nil)
- {
- DisposeHandle((Handle) drvrGlobalsHdl);
- SetDriverGlobals(nil);
- }
- }
-